cmake_minimum_required(VERSION 3.5)
project(hardware_interface)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Werror=conversion -Werror=unused-but-set-variable -Werror=return-type -Werror=shadow)
endif()

set(THIS_PACKAGE_INCLUDE_DEPENDS
    control_msgs
    lifecycle_msgs
    pluginlib
    rclcpp_lifecycle
    rcpputils
    rcutils
    tinyxml2_vendor
    TinyXML2
    shared_parameters
)

find_package(ament_cmake REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)

foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
  find_package(${Dependency} REQUIRED)
endforeach()

add_library(
  ${PROJECT_NAME}
  SHARED
  src/actuator.cpp
  src/component_parser.cpp
  src/resource_manager.cpp
  src/sensor.cpp
  src/system.cpp
  src/lexical_casts.cpp
)
target_include_directories(
  ${PROJECT_NAME}
  PUBLIC
  include
)
ament_target_dependencies(${PROJECT_NAME} ${THIS_PACKAGE_INCLUDE_DEPENDS})
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")

# Mock components
add_library(
  mock_components
  SHARED
  src/mock_components/generic_system.cpp
)
target_include_directories(
  mock_components
  PUBLIC
  include
)
target_link_libraries(
  mock_components
  ${PROJECT_NAME}
  Boost::system
)
ament_target_dependencies(
  mock_components
  pluginlib
  rcpputils
)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(mock_components PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")

pluginlib_export_plugin_description_file(
  ${PROJECT_NAME} mock_components_plugin_description.xml)

# Fake components
add_library(
  fake_components
  SHARED
  src/mock_components/generic_system.cpp
  src/mock_components/fake_generic_system.cpp
)
target_include_directories(
  fake_components
  PUBLIC
  include
)
target_link_libraries(
  fake_components
  ${PROJECT_NAME}
)
ament_target_dependencies(
  fake_components
  pluginlib
  rcpputils
)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(fake_components PRIVATE "HARDWARE_INTERFACE_BUILDING_DLL")

pluginlib_export_plugin_description_file(
  ${PROJECT_NAME} fake_components_plugin_description.xml)


install(
  DIRECTORY include/
  DESTINATION include
)

install(
  TARGETS
  fake_components
  mock_components
  ${PROJECT_NAME}
  RUNTIME DESTINATION bin
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
)

ament_export_include_directories(
  include
)
ament_export_libraries(
  fake_components
  mock_components
  ${PROJECT_NAME}
)
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
ament_package()
ament_generate_version_header(${PROJECT_NAME})
